package cn.stylefeng.guns.modular.api;

import cn.stylefeng.guns.modular.business.entity.MessageNotice;
import cn.stylefeng.guns.modular.business.model.result.MessageNoticeResult;
import cn.stylefeng.guns.modular.business.service.MessageNoticeService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("/gunsApi/message")
public class MessageNoticeApi extends BaseController {

    @Autowired
    MessageNoticeService messageNoticeService;

    @ApiOperation("根据类型获取消息")
    @GetMapping("/notice")
    public ResponseData getNoticeByType(@RequestParam String type) {
        Page<MessageNoticeResult> page = new Page<>();
        List<MessageNotice> list = messageNoticeService.list(page, null, type);
        List<MessageNoticeResult> messageNoticeResults = new ArrayList<>();
        list.forEach(messageNotice -> {
            MessageNoticeResult messageNoticeResult = new MessageNoticeResult();
            BeanUtils.copyProperties(messageNotice, messageNoticeResult);
            messageNoticeResults.add(messageNoticeResult);
        });
        page.setRecords(messageNoticeResults);
        return ResponseData.success(page);
    }

}


